package com.qinhailin.portal.business.service;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;
import com.qinhailin.common.vo.TreeNode;
import com.qinhailin.portal.business.model.IDeviceInfo;
import com.qinhailin.common.base.service.BaseService;
import com.qinhailin.common.vo.Grid;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ArrayNode;
import org.codehaus.jackson.node.ObjectNode;

import java.util.Collection;
import java.util.List;

/**
 * 
 * @author qinhailin
 * @date 2024-12-12
 */
public class IDeviceInfoService extends BaseService {
	private IDeviceInfo dao = new IDeviceInfo().dao();
    
    @Override
    public Model<IDeviceInfo> getDao(){
    	return dao;
    }

    public Grid page(int pageNumber, int pageSize,Record record) {
        Record rd = new Record();
        //rd.set("user_name like", record.getStr("keyword"));
        return queryForList(pageNumber, pageSize,rd);
    }

    public ObjectNode getDeviceInfo(String deviceId){
        String sql= Db.getSql("core.getDeviceInfo");
        List<Record> list = Db.find(sql, "%"+deviceId+"%");
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode json = mapper.createObjectNode();
        json.put("code",0);
        json.put("msg",0);
        json.put("count",list.size());
        ArrayNode arrayNode = mapper.createArrayNode();
        for (int i = 0; i < list.size(); i++) {
            Record func = list.get(i);
            ObjectNode node = mapper.createObjectNode();
            node.put("devideid",func.getStr("id"));
            node.put("binduser",func.getStr("name"));
            arrayNode.add(node);
        }
        json.put("data",arrayNode);
        return json;
    }

}
